 package com.oanda.blackberry.view;
 
 import com.oanda.blackberry.restapi.Price;
 import net.rim.device.api.ui.Color;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.CheckboxField;
 
 public class PriceField extends CheckboxField
 {
   Color fontColor;
   Font normal = Font.getDefault().derive(0, 14);
   Font bigger = Font.getDefault().derive(0, 22);
   Font small = Font.getDefault().derive(0, 10);
 
   private int backgroundColorFocused = 8421504;
   private int backgroundColorUnfocused = 11119017;
   private int textColorFocused = 16776960;
   private int textColorUnfocused = 32768;
 
   int horizontalPadding = 2;
   int verticalPadding = 2;
   Price price;
   boolean isFocused = false;
 
   public PriceField(long style, Price p) {
     this.price = p;
   }
 
   protected void layout(int maxWidth, int maxHeight) {
     int width = this.bigger.getAdvance(this.price.getPriceAsString()) + this.horizontalPadding * 2;
     int height = this.bigger.getHeight() + this.verticalPadding * 2;
     setExtent(width, height);
   }
 
   protected void paint(Graphics graphics)
   {
     super.paint(graphics);
     graphics.setColor(isFocus() ? this.backgroundColorFocused : this.backgroundColorUnfocused);
     graphics.fillRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
 
     graphics.setColor(isFocus() ? this.textColorFocused : this.textColorUnfocused);
     graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
 
     graphics.setFont(this.normal);
     graphics.drawText(this.price.getBaseString(), this.horizontalPadding, this.verticalPadding);
     graphics.setFont(this.bigger);
     graphics.drawText(this.price.getMainPriceString(), this.horizontalPadding + this.normal.getAdvance(this.price.getBaseString()), this.verticalPadding);
 
     graphics.setFont(this.small);
     graphics.drawText(this.price.getPippetteString(), this.horizontalPadding + this.normal.getAdvance(this.price.getBaseString()) + this.bigger.getAdvance(this.price.getMainPriceString()), this.verticalPadding);
   }
 
   public boolean isFocusable()
   {
     return true;
   }
 
   protected void drawFocus(Graphics graphics, boolean on)
   {
   }
 
   protected void onFocus(int direction) {
     this.isFocused = true;
     super.onFocus(direction);
     invalidate();
   }
 
   protected void onUnfocus() {
     this.isFocused = false;
     super.onUnfocus();
     invalidate();
   }
}

